#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
   connect(&cancel, SIGNAL(clicked()),this,SLOT(close()) );
   connect(&open, SIGNAL(clicked()),this,SLOT(openf()) );
   connect(&pole, SIGNAL(currentIndexChanged(QString)),this,SLOT(vive()));
   connect(&save, SIGNAL(clicked()),this,SLOT(saveF()) );

}

MainWindow::~MainWindow()
{}
    void MainWindow::openf()
{

ql = QFileDialog::getExistingDirectory(this, "Open");
QDir papka(ql);
QStringList filter;
filter<<"*txt";
spisok=papka.entryList(filter);
pole.addItems(spisok);
}
void MainWindow::vive()
{

    QFile file((ql+char(92)+pole.currentText()));
    file.open(QIODevice::ReadWrite | QIODevice::Text);
    QTextStream in(&file);
    QString txt;
    edit.setText("");
    txt=in.readLine();
    while (txt!="")
    {
        edit.append(txt);
        txt=in.readLine();
    }
    file.close();
}

void MainWindow::saveF()
    {
        QString ab=edit.toPlainText();
        QFile file((ql+char(92)+pole.currentText()));
        file.open(QIODevice::ReadWrite | QIODevice::Text);
        QTextStream out(&file);
        out<<ab;
        file.close();
    }

